package com.wangzhenyu.learn.test.designPattern

//组合模式

@Suppress("UNUSED")
object JCompositePattern {


    abstract class OrganizationComponent(val name: String, val desc: String) {


        open fun add(organizationComponent: OrganizationComponent) {

        }

        open fun remove(organizationComponent: OrganizationComponent) {

        }

        abstract fun print()

    }


    class University(name: String, desc: String) : OrganizationComponent(name, desc) {

        private val organizationComponents = mutableListOf<OrganizationComponent>()


        override fun add(organizationComponent: OrganizationComponent) {
            organizationComponents.add(organizationComponent)
        }

        override fun remove(organizationComponent: OrganizationComponent) {
            organizationComponents.remove(organizationComponent)
        }

        override fun print() {
            println(name)
            for (i in organizationComponents) {
                println(i.name)
            }
        }
    }

    class College(name: String, desc: String) : OrganizationComponent(name, desc) {

        private val organizationComponents = mutableListOf<OrganizationComponent>()


        override fun add(organizationComponent: OrganizationComponent) {
            organizationComponents.add(organizationComponent)
        }

        override fun remove(organizationComponent: OrganizationComponent) {
            organizationComponents.remove(organizationComponent)
        }

        override fun print() {
            println(name)
            for (i in organizationComponents) {
                println(i.name)
            }
        }
    }

    class Department(name: String, desc: String) : OrganizationComponent(name, desc) {

        override fun print() {
            println(name)
        }

    }


}